package com.idea.www.viewpagedemo;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2017/5/23.
 */

public class BannerAdapter extends PagerAdapter {

    private Context mContext;
    public BannerAdapter(Context context) {
        mContext = context;
    }


    private View mConvertView;

    @Override
    public int getCount() {
        return 2;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        if (position==0){
            mConvertView = LayoutInflater.from(mContext).inflate(R.layout.layout_item1, null);
        }else {
            mConvertView = LayoutInflater.from(mContext).inflate(R.layout.layout_item2, null);
        }

        mConvertView.setClickable(true);



        container.addView(mConvertView);
        return mConvertView;
    }

}
